package movieRental;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @author FanRuikang
 * @ClassName: Customer 
 * @Description: 顾客及其租赁信息
 * @date: 2018年6月19日 下午3:05:47 
 */
public class Customer {
	private String _name;
	private Vector _rentals  = new Vector();
	public Customer(String name) {
		_name = name;
	}

	public void addRental(Rental arg) {
		_rentals.addElement(arg);
	}

	public String getName() {
		return _name;
	}

	/**
	 * @Title: statement 
	 * @Description: 制造报表
	 * @return String
	 * @author FanRuikang
	 * @date 2018年6月19日下午3:14:30
	 */
	public String statement() {
		String result = "Rental Record for "+ getName() + "\n";
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			result += "\t" + rental.get_movie().get_title()+ "\t" + String.valueOf(rental.getCharge())+"\n";
		}
		
		result += "Amount owed is "+ String.valueOf(getTotalCharge())+"\n";
		result += "You earned" + String.valueOf(getTotalFrequentRenterPoints())+"frequent renter points";
		return result;
	}
	
	public String htmlStatement() {
		String result = "<H1>Rental Record for <EM> "+ getName() + "</EM></H1><P>\n";
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			result += "\t" + rental.get_movie().get_title()+ "\t" + String.valueOf(rental.getCharge())+"<BR>\n";
		}
		
		result += "<P>Amount owed is <EM>"+ String.valueOf(getTotalCharge())+"</EM></P>\n";
		result += "You earned<EM>" + 
		String.valueOf(getTotalFrequentRenterPoints())+
		"</EM>frequent renter points</P>";
		return result;
		
	}

	private double getTotalFrequentRenterPoints() {
		int result = 0;
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			result += rental.getFrequentRenterPoints();
		}
		return result;
	}

	private double getTotalCharge() {
		// TODO 自动生成的方法存根
		double result = 0;
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			result += rental.getCharge();
		}
		return result;
	}
}
